package cn.tedu.csmall.business.rabbit;

import cn.tedu.csmall.commons.pojo.order.model.Order;
import org.apache.commons.lang.math.RandomUtils;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class RabbitProducer {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    int i=1;
    @Scheduled(fixedRate = 10000)
    public void send(){
        Order order=new Order();
        order.setId(i++);
        order.setCommodityCode("PC100");
        order.setUserId("UU100");
        order.setMoney(RandomUtils.nextInt(100)+20);
        order.setCount(RandomUtils.nextInt(20)+1);

        rabbitTemplate.convertAndSend(
                RabbitMQConfig.BUSINESS_EX,
                RabbitMQConfig.BUSINESS_ROUT,
                order
        );
        System.out.println("发送了消息:"+order);

    }

}
